package com.ruoyi.web.message.controller;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.message.dto.SendMessageVo;
import com.ruoyi.web.message.dto.UserMessageDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.message.domain.MessageUser;
import com.ruoyi.web.message.service.IMessageUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息发送Controller
 *
 * @author 范书铭
 * @date 2024-10-11
 */
@Api("消息发送")
@RestController
@RequestMapping("/message/user")
public class MessageUserController extends BaseController {
    @Autowired
    private IMessageUserService messageUserService;


    /**
     * 发送消息
     * @param sendMessageDto
     * @return
     */
    @ApiOperation("发送消息")
    @PreAuthorize("@ss.hasPermi('message:user:export')")
    @Log(title = "发送消息", businessType = BusinessType.EXPORT)
    @PostMapping("/send")
    public AjaxResult send(@RequestBody SendMessageVo sendMessageDto) {
        return toAjax(messageUserService.send(sendMessageDto));
    }

    /**
     * 用户查询消息发送列表
     */
    @ApiOperation("查询消息发送列表")
    @PreAuthorize("@ss.hasPermi('message:user:list')")
    @GetMapping("/listUserMessage")
    public TableDataInfo listUserMessage(@RequestParam Boolean isRead ) {
        startPage();
        List<UserMessageDto> list = messageUserService.listUserMessage(SecurityUtils.getUserId(),isRead);
        return getDataTable(list);
    }
}
